#ifndef __CLIENT_H
#define __CLIENT_H
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
/* 显示屏相关头文件 */
#include <linux/fb.h>
#include <sys/mman.h>

#include <iostream>
#include <opencv2/opencv.hpp>

#define BLACK  "\e[30;1m"
#define RED    "\e[31;1m"
#define GREEN  "\e[32;1m"
#define YELLOW "\e[33;1m" 
#define BLUE   "\e[34;1m" 
#define PURPLE "\e[35;1m" 
#define CYAN   "\e[36;1m" 
#define WHITE  "\e[37;1m"
#define END    "\033[0m\n"

#define Print_BLACK(fmt,...)  printf(BLACK fmt END,##__VA_ARGS__)
#define Print_RED(fmt,...)    printf(RED fmt END,##__VA_ARGS__)
#define Print_GREEN(fmt,...)  printf(GREEN fmt END,##__VA_ARGS__)
#define Print_YELLOW(fmt,...) printf(YELLOW fmt END,##__VA_ARGS__)
#define Print_BLUE(fmt,...)   printf(BLUE fmt END,##__VA_ARGS__)
#define Print_PURPLE(fmt,...) printf(PURPLE fmt END,##__VA_ARGS__)
#define Print_CYAN(fmt,...)   printf(CYAN fmt END,##__VA_ARGS__)
#define Print_WHITE(fmt,...)  printf(WHITE fmt END,##__VA_ARGS__)

#define ERROR(msg) do{\
                    printf("file[%s],func[%s],line[%d]:",__FILE__,__func__,__LINE__);\
                    perror(RED msg END);\
                    exit(-1);\
                    }while(0);

#define NB_BUFFER 6
#define WIDTH  640
#define HEIGHT 480
#define LENGTH 4147789

class Framebuffer
{
public:
    Framebuffer();
    ~Framebuffer();
    int Init();
    int getFramebufferinfo();
    int display_rgb_to_framebuffer(unsigned char* rgb_data,int height,int width);
    int closeFramebuffer();

    int iFd;
    int iWidth;
    int iHeight;
    int rgb_type;
    long screen_size; 
    unsigned char* fbMapMem;
};

class client
{
public:
    client();
    ~client();
    void Init(const char *argv[]);
    void recv_rgb_data(Framebuffer *ptFramebuffer);
    void new_resized_rgb_data(Framebuffer *ptFramebuffer);
    void rgb_to_image(const char* filename);
    void decode_image(unsigned char* jpg_data, int new_width, int new_height, unsigned char* resized_rgb_data);
    void resizeRGB(unsigned char* rgb_data, int width, int height, unsigned char* resized_rgb_data, int new_width, int new_height);

    int n;
    int sockfd;
    unsigned char* rgb_data[NB_BUFFER];
    unsigned char* resized_rgb_data[NB_BUFFER];
};

#endif